package com.mxt.moviedemo.service.impl;

import com.mxt.moviedemo.dao.UserMapper;
import com.mxt.moviedemo.entity.User;
import com.mxt.moviedemo.service.UserService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
    @Resource
    private UserMapper userMapper;


    @Override
    public User loginForPhone(String phone, String password) {
        System.out.println("phone: " + phone + ", pwd: " + password);
        return userMapper.loginForPhone(phone, password);
    }

    @Override
    public User loginForEmail(String email, String password) {
        return userMapper.loginForEmail(email, password);
    }

    @Override
    public User loginByUsernameAndPassword(String uname, String password, String role) {
        System.out.println("uname" + uname + ", password" + password);
        return userMapper.loginByUsernameAndPassword(uname, password, role);
    }

    @Override
    public int registerUser(User user) {
        // 获取下一个可用的 uid
        int nextUid = getNextUid();
        user.setUidAndUuid(nextUid);

        // 加密密码

        user.setPassword(user.getPassword());

        return userMapper.registerUser(user);
    }

    @Override
    public int getNextUid() {
        return userMapper.getNextUid();
    }
}